package de.tud.etit.blipz.services.json;

import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import de.tud.etit.blipz.entities.Position;

public class PositionSerializer implements JsonSerializer<Position> {

	@Override
	public JsonElement serialize(Position position, Type type,
			JsonSerializationContext ctx) {

		if (position == null) {
			return null;
		}

		Long timestamp = position.getTimestamp().getTime() / 1000;

		JsonObject jsonObject = new JsonObject();
		jsonObject.addProperty("latitudeE6", position.getLatitudeE6());
		jsonObject.addProperty("longitudeE6", position.getLongitutdeE6());
		jsonObject.addProperty("timestamp", timestamp);

		return jsonObject;
	}
}
